package com.turing.post.salesmanage.impl;

import java.util.List;

import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import com.turing.post.salesmanage.util.RiskLevelChangeDetail;
import com.turing.post.salesmanage.util.RiskLevelChangeDetailDao;
import com.turing.post.util.GeneralDao;
import com.turing.post.util.PCPSApplicationException;
import com.turing.post.util.PCPSUtil;

/**
 * @author zxp
 * @Mar 15, 2013
 */
@Stateless(mappedName = "salesmanage.impl.RiskLevelChangeDetailDaoImpl")
@Remote
@Local
public class RiskLevelChangeDetailDaoImpl implements RiskLevelChangeDetailDao {

	@PersistenceContext
	protected EntityManager _em;

	@Override
	public void insert(RiskLevelChangeDetail rlcd)
			throws PCPSApplicationException {
		GeneralDao.insert(_em, rlcd);
	}  
	/**
	 * @根据类型和id检索变更列表
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<RiskLevelChangeDetail> getRiskLevelChangeDetailListByTyId(String issuecompanyno,String entityType,String entityID){
		 if(PCPSUtil.isEmpty(issuecompanyno)|| PCPSUtil.isEmpty(entityType) || PCPSUtil.isEmpty(entityID))
			 return null;
		 String sql="select * from RiskLevelChangeDetail where EntityType=?1 and EntityID=?2 and IssueCompanyNo=?3";
		 Query query=_em.createNativeQuery(sql, RiskLevelChangeDetail.class);
		 query.setParameter(1, entityType);
		 query.setParameter(2, entityID);
		 query.setParameter(3, issuecompanyno);
		 return query.getResultList();
	}
}
